package gang.org.springframework.framework.metadata;

import gang.org.springframework.framework.type.GangMethodMetadata;

import java.lang.annotation.Annotation;
import java.util.Collections;
import java.util.LinkedHashMap;
import java.util.LinkedHashSet;
import java.util.Set;
import java.util.stream.Collectors;
import java.util.stream.Stream;

public interface GangAnnotationMetadata extends GangClassMetadata,GangAnnotatedTypeMetadata {


    /**
     * @param type {@link com.gang.mars.boot.SpringbootManualApplication}
     * */
    static GangAnnotationMetadata introspect(Class<?> type)
    {
        return GangStandardAnnotationMetadata.from(type);
    }

    Set<GangMethodMetadata> getAnnotatedMethods(String annotationName);

    /**
     * 业务说明 获取任意类上的注解，举例说明
     * 1）ServletWebServerFactoryAutoConfiguration.java 配置类
     * 2) 配置类上的注解
     * 2.1 字符 AutoConfiguration
     * 2.2 字符 AutoConfigureOrder
     * 2.3 字符 ConditionalOnClass
     * 2.4 字符 ConditionalOnWebApplication
     * 2.5 字符 EnableConfigurationProperties
     * 2.6 字符 Import
     * */
    default Set<String> getAnnotationTypes(){

        //TODO

        GangMergedAnnotations annotations = getAnnotations();

        Stream<GangMergedAnnotation<Annotation>> stream = annotations.stream();

        if (stream != null) {

            LinkedHashSet<String> collect = stream.map(annotation -> annotation.getType().getName()).collect(Collectors.toCollection(LinkedHashSet::new));


            return collect;

        }

        /**
         * 如果获取不到注解字符，则返回 EmptySet
         * */
        return Collections.emptySet();

    }
}
